package com.one.efaimaly.main.ui.activity;


import android.content.Intent;
import android.widget.FrameLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.manager.event.BusManager;
import com.one.common.model.extra.DefaultExtra;
import com.one.common.utils.Logger;
import com.one.common.utils.ResourceUtils;
import com.one.common.view.base.BaseFragment;
import com.one.common.view.base.BaseFragmentActivity;
import com.one.common.view.bottombar.BottomBarBean;
import com.one.common.view.bottombar.BottomBarView;
import com.one.common.view.bottombar.OnBottomBarSelectListener;
import com.one.efaimaly.R;
import com.one.efaimaly.main.model.event.SelectCityEvent;
import com.one.efaimaly.main.ui.fragment.HomeFragment;
import com.one.efaimaly.main.ui.fragment.MyFragment;
import com.one.efaimaly.main.ui.fragment.OrderFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.jpush.android.api.JPushInterface;

@Route(path = RouterPath.MAIN_PAGE)
public class MainActivity extends BaseFragmentActivity {


    @BindView(R.id.frame_content)
    FrameLayout frameContent;
    @BindView(R.id.bbv)
    BottomBarView bbv;

    @Override
    protected void initPresenter() {
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_main;
    }


    @Override
    protected int getContainerViewId() {
        return R.id.frame_content;
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        noHasTitle();
    }

    @Override
    public void initView() {
        super.initView();
        initBottom();
    }

    /**
     * 初始化底部布局
     */
    private void initBottom() {
        List<BottomBarBean> bottomBarBeans = new ArrayList<>();

        BottomBarBean bean1 = new BottomBarBean();
        bean1.setText(ResourceUtils.getString(R.string.index_home));
        bean1.setDefaultIcon(R.mipmap.ic_index_home);
        bean1.setDefaultSelectIcon(R.mipmap.ic_index_home_check);

        BottomBarBean bean2 = new BottomBarBean();
        bean2.setText(ResourceUtils.getString(R.string.index_order));
        bean2.setDefaultIcon(R.mipmap.ic_index_order);
        bean2.setDefaultSelectIcon(R.mipmap.ic_index_order_check);

        BottomBarBean bean3 = new BottomBarBean();
        bean3.setText(ResourceUtils.getString(R.string.index_my));
        bean3.setDefaultIcon(R.mipmap.ic_index_my);
        bean3.setDefaultSelectIcon(R.mipmap.ic_index_my_check);

        bottomBarBeans.add(bean1);
        bottomBarBeans.add(bean2);
        bottomBarBeans.add(bean3);

        bbv.bindData(bottomBarBeans);
        bbv.bindTopView(frameContent);
        bbv.setTextSelectorLocalColor(R.color.text_color_90, R.color.text_color_blue);

        bbv.setOnBottomBarSelectListener(new OnBottomBarSelectListener() {
            @Override
            public void onSelect(int index, BottomBarBean bean) {
                changePage(index);
            }
        });
        bbv.setCheck(0);
        changePage(0);
    }

    @Override
    protected ArrayList<BaseFragment> getFragments() {
        ArrayList<BaseFragment> fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new OrderFragment());
        fragments.add(new MyFragment());

        return fragments;
    }


    @Override
    public void initData() {
        super.initData();

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK){
            String city = data.getStringExtra(DefaultExtra.getExtraName());
            BusManager.getBus().post(new SelectCityEvent(city));
        }
    }
}
